home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / include / gnulib2.h < prev    next >
C/C++ Source or Header  |  1990-03-09  |  16KB  |  848 lines

  1. /* More subroutines needed by GCC output code on some machines.  */
  2. /* Compile this one with gcc.  */
  3.  
  4. #include "config.h"
  5. #include <stddef.h>
  6.  
  7. #ifndef SItype
  8. #define SItype long int
  9. #endif
  10.  
  11. /* long long ints are pairs of long ints in the order determined by
  12.    WORDS_BIG_ENDIAN.  */
  13.  
  14. #ifdef WORDS_BIG_ENDIAN
  15.   struct longlong {long high, low;};
  16. #else
  17.   struct longlong {long low, high;};
  18. #endif
  19.  
  20. /* We need this union to unpack/pack longlongs, since we don't have
  21.    any arithmetic yet.  Incoming long long parameters are stored
  22.    into the `ll' field, and the unpacked result is read from the struct
  23.    longlong.  */
  24.  
  25. typedef union
  26. {
  27.   struct longlong s;
  28.   long long ll;
  29.   SItype i[2];
  30.   unsigned SItype ui[2];
  31. } long_long;
  32.  
  33. /* Internally, long long ints are strings of unsigned shorts in the
  34.    order determined by BYTES_BIG_ENDIAN.  */
  35.  
  36. #define B 0x10000
  37. #define low16 (B - 1)
  38.  
  39. #ifdef BYTES_BIG_ENDIAN
  40.  
  41. /* Note that HIGH and LOW do not describe the order
  42.    of words in a long long.  They describe the order of words
  43.    in vectors ordered according to the byte order.  */
  44.  
  45. #define HIGH 0
  46. #define LOW 1
  47.  
  48. #define big_end(n)    0 
  49. #define little_end(n)    ((n) - 1)
  50. #define next_msd(i)    ((i) - 1)
  51. #define next_lsd(i)    ((i) + 1)
  52. #define is_not_msd(i,n)    ((i) >= 0)
  53. #define is_not_lsd(i,n)    ((i) < (n))
  54.  
  55. #else
  56.  
  57. #define LOW 0
  58. #define HIGH 1
  59.  
  60. #define big_end(n)    ((n) - 1)
  61. #define little_end(n)    0 
  62. #define next_msd(i)    ((i) + 1)
  63. #define next_lsd(i)    ((i) - 1)
  64. #define is_not_msd(i,n)    ((i) < (n))
  65. #define is_not_lsd(i,n)    ((i) >= 0)
  66.  
  67. #endif
  68.  
  69. /* These algorithms are all straight out of Knuth, vol. 2, sec. 4.3.1. */
  70.  
  71. static int badd ();
  72. static int bsub ();
  73. static void bmul ();
  74. static int bneg ();
  75. static int bshift ();
  76.  
  77. #ifdef L_adddi3
  78. long long 
  79. __adddi3 (u, v)
  80.      long long u, v;
  81. {
  82.   long a[2], b[2], c[2];
  83.   long_long w;
  84.   long_long uu, vv;
  85.  
  86.   uu.ll = u;
  87.   vv.ll = v;
  88.  
  89.   a[HIGH] = uu.s.high;
  90.   a[LOW] = uu.s.low;
  91.   b[HIGH] = vv.s.high;
  92.   b[LOW] = vv.s.low;
  93.  
  94.   badd (a, b, c, sizeof c);
  95.  
  96.   w.s.high = c[HIGH];
  97.   w.s.low = c[LOW];
  98.   return w.ll;
  99. }
  100.  
  101. static int 
  102. badd (a, b, c, n)
  103.      unsigned short *a, *b, *c;
  104.      size_t n;
  105. {
  106.   unsigned long acc;
  107.   int i;
  108.  
  109.   n /= sizeof *c;
  110.  
  111.   acc = 0;
  112.   for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  113.     {
  114.       /* Widen before adding to avoid loss of high bits.  */
  115.       acc += (unsigned long) a[i] + b[i];
  116.       c[i] = acc & low16;
  117.       acc = acc >> 16;
  118.     }
  119.   return acc;
  120. }
  121. #endif
  122.  
  123. #ifdef L_anddi3
  124. long long 
  125. __anddi3 (u, v)
  126.      long long u, v;
  127. {
  128.   long_long w;
  129.   long_long uu, vv;
  130.  
  131.   uu.ll = u;
  132.   vv.ll = v;
  133.  
  134.   w.s.high = uu.s.high & vv.s.high;
  135.   w.s.low = uu.s.low & vv.s.low;
  136.  
  137.   return w.ll;
  138. }
  139. #endif
  140.  
  141. #ifdef L_iordi3
  142. long long 
  143. __iordi3 (u, v)
  144.      long long u, v;
  145. {
  146.   long_long w;
  147.   long_long uu, vv;
  148.  
  149.   uu.ll = u;
  150.   vv.ll = v;
  151.  
  152.   w.s.high = uu.s.high | vv.s.high;
  153.   w.s.low = uu.s.low | vv.s.low;
  154.  
  155.   return w.ll;
  156. }
  157. #endif
  158.  
  159. #ifdef L_xordi3
  160. long long 
  161. __xordi3 (u, v)
  162.      long long u, v;
  163. {
  164.   long_long w;
  165.   long_long uu, vv;
  166.  
  167.   uu.ll = u;
  168.   vv.ll = v;
  169.  
  170.   w.s.high = uu.s.high ^ vv.s.high;
  171.   w.s.low = uu.s.low ^ vv.s.low;
  172.  
  173.   return w.ll;
  174. }
  175. #endif
  176.  
  177. #ifdef L_one_cmpldi2
  178. long long
  179. __one_cmpldi2 (u)
  180.      long long u;
  181. {
  182.   long_long w;
  183.   long_long uu;
  184.  
  185.   uu.ll = u;
  186.  
  187.   w.s.high = ~uu.s.high;
  188.   w.s.low = ~uu.s.low;
  189.  
  190.   return w.ll;
  191. }
  192. #endif
  193.  
  194. #ifdef L_lshldi3
  195. long long
  196. __lshldi3 (u, b)
  197.      long long u;
  198.      long int b;
  199. {
  200.   long_long w;
  201.   unsigned long carries;
  202.   int bm;
  203.   long_long uu;
  204.  
  205.   if (b == 0)
  206.     return u;
  207.  
  208.   uu.ll = u;
  209.  
  210.   bm = (sizeof (int) * BITS_PER_UNIT) - b;
  211.   if (bm <= 0)
  212.     {
  213.       w.s.low = 0;
  214.       w.s.high = (unsigned long)uu.s.low << -bm;
  215.     }
  216.   else
  217.     {
  218.       carries = (unsigned long)uu.s.low >> bm;
  219.       w.s.low = (unsigned long)uu.s.low << b;
  220.       w.s.high = ((unsigned long)uu.s.high << b) | carries;
  221.     }
  222.  
  223.   return w.ll;
  224. }
  225. #endif
  226.  
  227. #ifdef L_lshrdi3
  228. long long
  229. __lshrdi3 (u, b)
  230.      long long u;
  231.      long int b;
  232. {
  233.   long_long w;
  234.   unsigned long carries;
  235.   int bm;
  236.   long_long uu;
  237.  
  238.   if (b == 0)
  239.     return u;
  240.  
  241.   uu.ll = u;
  242.  
  243.   bm = (sizeof (int) * BITS_PER_UNIT) - b;
  244.   if (bm <= 0)
  245.     {
  246.       w.s.high = 0;
  247.       w.s.low = (unsigned long)uu.s.high >> -bm;
  248.     }
  249.   else
  250.     {
  251.       carries = (unsigned long)uu.s.high << bm;
  252.       w.s.high = (unsigned long)uu.s.high >> b;
  253.       w.s.low = ((unsigned long)uu.s.low >> b) | carries;
  254.     }
  255.  
  256.   return w.ll;
  257. }
  258. #endif
  259.  
  260. #ifdef L_ashldi3
  261. long long
  262. __ashldi3 (u, b)
  263.      long long u;
  264.      long int b;
  265. {
  266.   long_long w;
  267.   unsigned long carries;
  268.   int bm;
  269.   long_long uu;
  270.  
  271.   if (b == 0)
  272.     return u;
  273.  
  274.   uu.ll = u;
  275.  
  276.   bm = (sizeof (int) * BITS_PER_UNIT) - b;
  277.   if (bm <= 0)
  278.     {
  279.       w.s.low = 0;
  280.       w.s.high = (unsigned long)uu.s.low << -bm;
  281.     }
  282.   else
  283.     {
  284.       carries = (unsigned long)uu.s.low >> bm;
  285.       w.s.low = (unsigned long)uu.s.low << b;
  286.       w.s.high = ((unsigned long)uu.s.high << b) | carries;
  287.     }
  288.  
  289.   return w.ll;
  290. }
  291. #endif
  292.  
  293. #ifdef L_ashrdi3
  294. long long
  295. __ashrdi3 (u, b)
  296.      long long u;
  297.      long int b;
  298. {
  299.   long_long w;
  300.   unsigned long carries;
  301.   int bm;
  302.   long_long uu;
  303.  
  304.   if (b == 0)
  305.     return u;
  306.  
  307.   uu.ll = u;
  308.  
  309.   bm = (sizeof (int) * BITS_PER_UNIT) - b;
  310.   if (bm <= 0)
  311.     {
  312.       w.s.high = uu.s.high >> 31; /* just to make w.s.high 1..1 or 0..0 */
  313.       w.s.low = uu.s.high >> -bm;
  314.     }
  315.   else
  316.     {
  317.       carries = (unsigned long)uu.s.high << bm;
  318.       w.s.high = uu.s.high >> b;
  319.       w.s.low = ((unsigned long)uu.s.low >> b) | carries;
  320.     }
  321.  
  322.   return w.ll;
  323. }
  324. #endif
  325.  
  326. #ifdef L_subdi3
  327. long long 
  328. __subdi3 (u, v)
  329.      long long u, v;
  330. {
  331.   long a[2], b[2], c[2];
  332.   long_long w;
  333.   long_long uu, vv;
  334.  
  335.   uu.ll = u;
  336.   vv.ll = v;
  337.  
  338.   a[HIGH] = uu.s.high;
  339.   a[LOW] = uu.s.low;
  340.   b[HIGH] = vv.s.high;
  341.   b[LOW] = vv.s.low;
  342.  
  343.   bsub (a, b, c, sizeof c);
  344.  
  345.   w.s.high = c[HIGH];
  346.   w.s.low = c[LOW];
  347.   return w.ll;
  348. }
  349.  
  350. static int 
  351. bsub (a, b, c, n)
  352.      unsigned short *a, *b, *c;
  353.      size_t n;
  354. {
  355.   signed long acc;
  356.   int i;
  357.  
  358.   n /= sizeof *c;
  359.  
  360.   acc = 0;
  361.   for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  362.     {
  363.       /* Widen before subtracting to avoid loss of high bits.  */
  364.       acc += (long) a[i] - b[i];
  365.       c[i] = acc & low16;
  366.       acc = acc >> 16;
  367.     }
  368.   return acc;
  369. }
  370. #endif
  371.  
  372. #ifdef L_muldi3
  373. long long 
  374. __muldi3 (u, v)
  375.      long long u, v;
  376. {
  377.   long a[2], b[2], c[2][2];
  378.   long_long w;
  379.   long_long uu, vv;
  380.  
  381.   uu.ll = u;
  382.   vv.ll = v;
  383.  
  384.   a[HIGH] = uu.s.high;
  385.   a[LOW] = uu.s.low;
  386.   b[HIGH] = vv.s.high;
  387.   b[LOW] = vv.s.low;
  388.  
  389.   bmul (a, b, c, sizeof a, sizeof b);
  390.  
  391.   w.s.high = c[LOW][HIGH];
  392.   w.s.low = c[LOW][LOW];
  393.   return w.ll;
  394. }
  395.  
  396. static void 
  397. bmul (a, b, c, m, n)
  398.     unsigned short *a, *b, *c;
  399.     size_t m, n;
  400. {
  401.   int i, j;
  402.   unsigned long acc;
  403.  
  404.   bzero (c, m + n);
  405.  
  406.   m /= sizeof *a;
  407.   n /= sizeof *b;
  408.  
  409.   for (j = little_end (n); is_not_msd (j, n); j = next_msd (j))
  410.     {
  411.       unsigned short *c1 = c + j + little_end (2);
  412.       acc = 0;
  413.       for (i = little_end (m); is_not_msd (i, m); i = next_msd (i))
  414.     {
  415.       /* Widen before arithmetic to avoid loss of high bits.  */
  416.       acc += (unsigned long) a[i] * b[j] + c1[i];
  417.       c1[i] = acc & low16;
  418.       acc = acc >> 16;
  419.     }
  420.       c1[i] = acc;
  421.     }
  422. }
  423. #endif
  424.  
  425. #ifdef L_divdi3
  426. long long
  427. __divdi3 (u, v)
  428.      long long u, v;
  429. {
  430.   if (u < 0)
  431.     if (v < 0)
  432.       return (unsigned long long) -u / (unsigned long long) -v;
  433.     else
  434.       return - ((unsigned long long) -u / (unsigned long long) v);
  435.   else
  436.     if (v < 0)
  437.       return - ((unsigned long long) u / (unsigned long long) -v);
  438.     else
  439.       return (unsigned long long) u / (unsigned long long) v;
  440. }
  441. #endif
  442.  
  443. #ifdef L_moddi3
  444. long long
  445. __moddi3 (u, v)
  446.      long long u, v;
  447. {
  448.   if (u < 0)
  449.     if (v < 0)
  450.       return - ((unsigned long long) -u % (unsigned long long) -v);
  451.     else
  452.       return - ((unsigned long long) -u % (unsigned long long) v);
  453.   else
  454.     if (v < 0)
  455.       return (unsigned long long) u % (unsigned long long) -v;
  456.     else
  457.       return (unsigned long long) u % (unsigned long long) v;
  458. }
  459. #endif
  460.  
  461. #ifdef L_udivdi3
  462. long long 
  463. __udivdi3 (u, v)
  464.      long long u, v;
  465. {
  466.   unsigned long a[2][2], b[2], q[2], r[2];
  467.   long_long w;
  468.   long_long uu, vv;
  469.  
  470.   uu.ll = u;
  471.   vv.ll = v;
  472.  
  473.   a[HIGH][HIGH] = 0;
  474.   a[HIGH][LOW] = 0;
  475.   a[LOW][HIGH] = uu.s.high;
  476.   a[LOW][LOW] = uu.s.low;
  477.   b[HIGH] = vv.s.high;
  478.   b[LOW] = vv.s.low;
  479.  
  480.   __bdiv (a, b, q, r, sizeof a, sizeof b);
  481.  
  482.   w.s.high = q[HIGH];
  483.   w.s.low = q[LOW];
  484.   return w.ll;
  485. }
  486. #endif
  487.  
  488. #ifdef L_umoddi3
  489. long long 
  490. __umoddi3 (u, v)
  491.      long long u, v;
  492. {
  493.   unsigned long a[2][2], b[2], q[2], r[2];
  494.   long_long w;
  495.   long_long uu, vv;
  496.  
  497.   uu.ll = u;
  498.   vv.ll = v;
  499.  
  500.   a[HIGH][HIGH] = 0;
  501.   a[HIGH][LOW] = 0;
  502.   a[LOW][HIGH] = uu.s.high;
  503.   a[LOW][LOW] = uu.s.low;
  504.   b[HIGH] = vv.s.high;
  505.   b[LOW] = vv.s.low;
  506.  
  507.   __bdiv (a, b, q, r, sizeof a, sizeof b);
  508.  
  509.   w.s.high = r[HIGH];
  510.   w.s.low = r[LOW];
  511.   return w.ll;
  512. }
  513. #endif
  514.  
  515. #ifdef L_negdi2
  516. long long 
  517. __negdi2 (u)
  518.      long long u;
  519. {
  520.   unsigned long a[2], b[2];
  521.   long_long w;
  522.   long_long uu;
  523.  
  524.   uu.ll = u;
  525.  
  526.   a[HIGH] = uu.s.high;
  527.   a[LOW] = uu.s.low;
  528.  
  529.   bneg (a, b, sizeof b);
  530.  
  531.   w.s.high = b[HIGH];
  532.   w.s.low = b[LOW];
  533.   return w.ll;
  534. }
  535.  
  536. static int
  537. bneg (a, b, n)
  538.      unsigned short *a, *b;
  539.      size_t n;
  540. {
  541.   signed long acc;
  542.   int i;
  543.  
  544.   n /= sizeof (short);
  545.  
  546.   acc = 0;
  547.   for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  548.     {
  549.       acc -= a[i];
  550.       b[i] = acc & low16;
  551.       acc = acc >> 16;
  552.     }
  553.   return acc;
  554. }
  555. #endif
  556.  
  557. /* Divide a by b, producing quotient q and remainder r.
  558.  
  559.        sizeof a is m
  560.        sizeof b is n
  561.        sizeof q is m - n
  562.        sizeof r is n
  563.  
  564.    The quotient must fit in m - n bytes, i.e., the most significant
  565.    n digits of a must be less than b, and m must be greater than n.  */
  566.  
  567. /* The name of this used to be __div_internal,
  568.    but that is too long for SYSV.  */
  569.  
  570. #ifdef L_bdiv
  571. void 
  572. __bdiv (a, b, q, r, m, n)
  573.      unsigned short *a, *b, *q, *r;
  574.      size_t m, n;
  575. {
  576.   unsigned long qhat, rhat;
  577.   unsigned long acc;
  578.   unsigned short *u = (unsigned short *) alloca (m);
  579.   unsigned short *v = (unsigned short *) alloca (n);
  580.   unsigned short *u0, *u1, *u2;
  581.   unsigned short *v0;
  582.   int d, qn;
  583.   int i, j;
  584.  
  585.   m /= sizeof *a;
  586.   n /= sizeof *b;
  587.   qn = m - n;
  588.  
  589.   /* Remove leading zero digits from divisor, and the same number of
  590.      digits (which must be zero) from dividend.  */
  591.  
  592.   while (b[big_end (n)] == 0)
  593.     {
  594.       r[big_end (n)] = 0;
  595.  
  596.       a += little_end (2);
  597.       b += little_end (2);
  598.       r += little_end (2);
  599.       m--;
  600.       n--;
  601.  
  602.       /* Check for zero divisor.  */
  603.       if (n == 0)
  604.     abort ();
  605.     }
  606.       
  607.   /* If divisor is a single digit, do short division.  */
  608.  
  609.   if (n == 1)
  610.     {
  611.       acc = a[big_end (m)];
  612.       a += little_end (2);
  613.       for (j = big_end (qn); is_not_lsd (j, qn); j = next_lsd (j))
  614.     {
  615.       acc = (acc << 16) | a[j];
  616.       q[j] = acc / *b;
  617.       acc = acc % *b;
  618.     }
  619.       *r = acc;
  620.       return;
  621.     }
  622.  
  623.   /* No such luck, must do long division. Shift divisor and dividend
  624.      left until the high bit of the divisor is 1.  */
  625.  
  626.   for (d = 0; d < 16; d++)
  627.     if (b[big_end (n)] & (1 << (16 - 1 - d)))
  628.       break;
  629.  
  630.   bshift (a, d, u, 0, m);
  631.   bshift (b, d, v, 0, n);
  632.  
  633.   /* Get pointers to the high dividend and divisor digits.  */
  634.  
  635.   u0 = u + big_end (m) - big_end (qn);
  636.   u1 = next_lsd (u0);
  637.   u2 = next_lsd (u1);
  638.   u += little_end (2);
  639.  
  640.   v0 = v + big_end (n);
  641.  
  642.   /* Main loop: find a quotient digit, multiply it by the divisor,
  643.      and subtract that from the dividend, shifted over the right amount. */
  644.  
  645.   for (j = big_end (qn); is_not_lsd (j, qn); j = next_lsd (j))
  646.     {
  647.       /* Quotient digit initial guess: high 2 dividend digits over high
  648.      divisor digit.  */
  649.  
  650.       if (u0[j] == *v0)
  651.     {
  652.       qhat = B - 1;
  653.       rhat = (unsigned long) *v0 + u1[j];
  654.     }
  655.       else
  656.     {
  657.       unsigned long numerator = ((unsigned long) u0[j] << 16) | u1[j];
  658.       qhat = numerator / *v0;
  659.       rhat = numerator % *v0;
  660.     }
  661.  
  662.       /* Now get the quotient right for high 3 dividend digits over
  663.      high 2 divisor digits.  */
  664.  
  665.       while (rhat < B && qhat * *next_lsd (v0) > ((rhat << 16) | u2[j]))
  666.     {
  667.       qhat -= 1;
  668.       rhat += *v0;
  669.     }
  670.         
  671.       /* Multiply quotient by divisor, subtract from dividend.  */
  672.  
  673.       acc = 0;
  674.       for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  675.     {
  676.       acc += (unsigned long) (u + j)[i] - v[i] * qhat;
  677.       (u + j)[i] = acc & low16;
  678.       if (acc < B)
  679.         acc = 0;
  680.       else
  681.         acc = (acc >> 16) | -B;
  682.     }
  683.  
  684.       q[j] = qhat;
  685.  
  686.       /* Quotient may have been too high by 1.  If dividend went negative,
  687.      decrement the quotient by 1 and add the divisor back.  */
  688.  
  689.       if ((signed long) (acc + u0[j]) < 0)
  690.     {
  691.       q[j] -= 1;
  692.       acc = 0;
  693.       for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  694.         {
  695.           acc += (unsigned long) (u + j)[i] + v[i];
  696.           (u + j)[i] = acc & low16;
  697.           acc = acc >> 16;
  698.         }
  699.     }
  700.     }
  701.  
  702.   /* Now the remainder is what's left of the dividend, shifted right
  703.      by the amount of the normalizing left shift at the top.  */
  704.  
  705.   r[big_end (n)] = bshift (u + 1 + little_end (j - 1),
  706.                16 - d,
  707.                r + little_end (2),
  708.                u[little_end (m - 1)] >> d,
  709.                n - 1);
  710. }
  711.  
  712. /* Left shift U by K giving W; fill the introduced low-order bits with
  713.    CARRY_IN.  Length of U and W is N.  Return carry out.  K must be
  714.    in 0 .. 16.  */
  715.  
  716. static int
  717. bshift (u, k, w, carry_in, n)
  718.      unsigned short *u, *w, carry_in;
  719.      int k, n;
  720. {
  721.   unsigned long acc;
  722.   int i;
  723.  
  724.   if (k == 0)
  725.     {
  726.       bcopy (u, w, n * sizeof *u);
  727.       return 0;
  728.     }
  729.  
  730.   acc = carry_in;
  731.   for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  732.     {
  733.       acc |= (unsigned long) u[i] << k;
  734.       w[i] = acc & low16;
  735.       acc = acc >> 16;
  736.     }
  737.   return acc;
  738. }
  739. #endif
  740.  
  741. #ifdef L_cmpdi2
  742. SItype
  743. __cmpdi2 (a, b)
  744.      long long a, b;
  745. {
  746.   long_long au, bu;
  747.  
  748.   au.ll = a, bu.ll = b;
  749.  
  750.   if (au.s.high < bu.s.high)
  751.     return 0;
  752.   else if (au.s.high > bu.s.high)
  753.     return 2;
  754.   if ((unsigned) au.s.low < (unsigned) bu.s.low)
  755.     return 0;
  756.   else if ((unsigned) au.s.low > (unsigned) bu.s.low)
  757.     return 2;
  758.   return 1;
  759. }
  760. #endif
  761.  
  762. #ifdef L_ucmpdi2
  763. SItype
  764. __ucmpdi2 (a, b)
  765.      long long a, b;
  766. {
  767.   long_long au, bu;
  768.  
  769.   au.ll = a, bu.ll = b;
  770.  
  771.   if ((unsigned) au.s.high < (unsigned) bu.s.high)
  772.     return 0;
  773.   else if ((unsigned) au.s.high > (unsigned) bu.s.high)
  774.     return 2;
  775.   if ((unsigned) au.s.low < (unsigned) bu.s.low)
  776.     return 0;
  777.   else if ((unsigned) au.s.low > (unsigned) bu.s.low)
  778.     return 2;
  779.   return 1;
  780. }
  781. #endif
  782.  
  783. #ifdef L_fixunsdfdi
  784. #define HIGH_WORD_COEFF (((long long) 1) << BITS_PER_WORD)
  785.  
  786. long long
  787. __fixunsdfdi (a)
  788.      double a;
  789. {
  790.   double b;
  791.   unsigned long long v;
  792.  
  793.   if (a < 0)
  794.     return 0;
  795.  
  796.   /* Compute high word of result, as a flonum.  */
  797.   b = (a / HIGH_WORD_COEFF);
  798.   /* Convert that to fixed (but not to long long!),
  799.      and shift it into the high word.  */
  800.   v = (unsigned long int) b;
  801.   v <<= BITS_PER_WORD;
  802.   /* Remove high part from the double, leaving the low part as flonum.  */
  803.   a -= (double)v;
  804.   /* Convert that to fixed (but not to long long!) and add it in.
  805.      Sometimes A comes out negative.  This is significant, since
  806.      A has more bits than a long int does.  */
  807.   if (a < 0)
  808.     v -= (unsigned long int) (- a);
  809.   else
  810.     v += (unsigned long int) a;
  811.   return v;
  812. }
  813. #endif
  814.  
  815. #ifdef L_fixdfdi
  816. long long
  817. __fixdfdi (a)
  818.      double a;
  819. {
  820.   if (a < 0)
  821.     return - __fixunsdfdi (-a);
  822.   return __fixunsdfdi (a);
  823. }
  824. #endif
  825.  
  826. #ifdef L_floatdidf
  827. #define HIGH_HALFWORD_COEFF (((long long) 1) << (BITS_PER_WORD / 2))
  828. #define HIGH_WORD_COEFF (((long long) 1) << BITS_PER_WORD)
  829.  
  830. double
  831. __floatdidf (u)
  832.      long long u;
  833. {
  834.   double d;
  835.   int negate = 0;
  836.  
  837.   if (d < 0)
  838.     u = -u, negate = 1;
  839.  
  840.   d = (unsigned int) (u >> BITS_PER_WORD);
  841.   d *= HIGH_HALFWORD_COEFF;
  842.   d *= HIGH_HALFWORD_COEFF;
  843.   d += (unsigned int) (u & (HIGH_WORD_COEFF - 1));
  844.  
  845.   return (negate ? -d : d);
  846. }
  847. #endif
  848.